﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for Control
/// </summary>
public class Controller
{
    public Controller()
    {

    }

    #region Redirect Page
    public static void RedirectPage(HttpResponse Response, HttpRequest Request, int pageNumber)
    {
        string rootPage = Request.ApplicationPath;
        string url =  "";
        switch (pageNumber)
        {
            case 10000:
                url += "Admin/Components/Member/CreateMember.aspx";
                Response.Redirect(url);
                break;
            default:
                url += "Default.aspx";
                Response.Redirect(url);
                break;
        }

        //Ex : Control.RedirectPage(Response, Request, 1);
    }
    #endregion

    #region Load Control

    public static void LoadUserControl1(Page page, HttpRequest Request, PlaceHolder holder, string parentModule,string module, int catId)
    {
        string rootPage = Request.ApplicationPath;
        string url = "";
        string urlAdmin = "~/";

        System.Web.UI.Control control;

        #region Load Control Admin
        if (parentModule == "Admin")
        {
            // Module ben Admin
            if (module == "Member")
            {
                switch (catId)
                {
                    case 1: // Tao thanh vien
                        control = page.LoadControl(urlAdmin + "Admin/Components/Member/CreateMember.ascx");
                        holder.Controls.Add(control);
                        break;
                    case 2: // Phan quyen nguoi dung
                        control = page.LoadControl(urlAdmin + "Admin/Components/Member/PermissionUser.ascx");
                        holder.Controls.Add(control);
                        break;
                    case 3: // Phan quyen nguoi dung
                        control = page.LoadControl("Main.ascx");
                        holder.Controls.Add(control);
                        break;
                    default:
                        control = page.LoadControl(urlAdmin + "Admin/Home.ascx");
                        holder.Controls.Add(control);
                        break;
                }
            }//End Module Member

           
            else if (module == "Home")
            {
                switch (catId)
                {
                    case 1:
                        control = page.LoadControl("Main.ascx");
                        holder.Controls.Add(control);
                        break;
                    case 2: // Reset Password
                        control = page.LoadControl(urlAdmin + "Admin/Alert.ascx");
                        holder.Controls.Add(control);
                        break;
                    default:
                        control = page.LoadControl(urlAdmin + "Admin/Home.ascx");
                        holder.Controls.Add(control);
                        break;
                }
            }

            
            if (module == "Report")//Bao cao
            {
                switch (catId)
                {
                    case 1: // Bao cao cau hoi
                        control = page.LoadControl(urlAdmin + "Admin/Components/Report/Question.ascx");
                        holder.Controls.Add(control);
                        break;
                    case 2: // Bao cao de thi
                        control = page.LoadControl(urlAdmin + "Admin/Components/Report/Exam.ascx");
                        holder.Controls.Add(control);
                        break;
                    case 3: // Bao cao thanh vien
                        control = page.LoadControl(urlAdmin + "Admin/Components/Report/Member.ascx");
                        holder.Controls.Add(control);
                        break;
                }
            }//End Bao cao

        }
        //End admin
        #endregion

        #region Load Control User
        //User 
        else
        {
            if (module == "Home")//Trang chu
            {
                switch (catId)
                {
                    case 1: // Trang chu
                        //control = page.LoadControl("Components/Member/Login.ascx");
                        control = page.LoadControl("Main.ascx");
                        holder.Controls.Add(control);
                        break;
                }
            }
            
            else if (module == "UpdateInfoMember")
            {
                switch (catId)
                {
                    case 1:// Cap nhat thong tin ca nhan                
                        control = page.LoadControl(url + "Components/Member/UpdateInfoMember.ascx");
                        holder.Controls.Add(control);
                        break;
                    default: // Trang chu
                        control = page.LoadControl(url + "Components/Home/Home.ascx");
                        holder.Controls.Add(control);
                        break;
                }
            }
        }
        #endregion
    }

    //public static void LoadUserControl(Page page, HttpRequest Request, PlaceHolder holder, string parentModule, string module, int catId)
    //{
    //    string rootPage = Request.ApplicationPath;
    //    string url = "";
    //    string urlAdmin = "~/";

    //    System.Web.UI.Control control;

    //    #region Load Control Admin
    //    if (parentModule == "Admin")
    //    {
    //        // Module ben Admin
    //        if (module == "Member")
    //        {
    //            switch (catId)
    //            {
    //                case 1: // Tao thanh vien
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/Member/CreateMember.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 2: // Phan quyen nguoi dung
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/Member/PermissionUser.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 3: // Phan quyen nhom
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/Member/PermissionGroup.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 4: // Danh sach thanh vien
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/Member/ListMember.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 5: // Danh sach chuc nang
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/Member/ListFunction.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 6: // Login Admin
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/Member/Login.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 7: // Change Password
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/Member/ChangePassword.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 8: // Reset Password
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/Member/ResetPassword.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                default:
    //                    control = page.LoadControl(urlAdmin + "Admin/Home.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //            }
    //        }//End Module Member



    //        ////Report
    //        //else if (module == "Report")
    //        //{
    //        //    switch (catId)
    //        //    {
    //        //        case 1: // So UV du tuyen
    //        //            control = page.LoadControl(urlAdmin + "Admin/Components/Reports/CandidateJoin.ascx");
    //        //            holder.Controls.Add(control);
    //        //            break;
    //        //        case 2: // So UV trung tuyen
    //        //            control = page.LoadControl(urlAdmin + "Admin/Components/Reports/CandidatePass.ascx");
    //        //            holder.Controls.Add(control);
    //        //            break;
    //        //        case 3: // Ty le trung tuyen
    //        //            control = page.LoadControl(urlAdmin + "Admin/Components/Reports/CandidatePercentPass.ascx");
    //        //            holder.Controls.Add(control);
    //        //            break;
    //        //        case 4: // Kho UV
    //        //            control = page.LoadControl(urlAdmin + "Admin/Components/Reports/CandidateRepo.ascx");
    //        //            holder.Controls.Add(control);
    //        //            break;
    //        //        case 5: // So tin tuyen dung
    //        //            control = page.LoadControl(urlAdmin + "Admin/Components/Reports/RecruitmentNews.ascx");
    //        //            holder.Controls.Add(control);
    //        //            break;
    //        //        case 6: // So CV them moi
    //        //            control = page.LoadControl(urlAdmin + "Admin/Components/Reports/ResumeNewAdd.ascx");
    //        //            holder.Controls.Add(control);
    //        //            break;
    //        //        case 7: // So thanh vien quan tri
    //        //            control = page.LoadControl(urlAdmin + "Admin/Components/Reports/MemberQuantity.ascx");
    //        //            holder.Controls.Add(control);
    //        //            break;
    //        //        default:
    //        //            control = page.LoadControl(urlAdmin + "Admin/Home.ascx");
    //        //            holder.Controls.Add(control);
    //        //            break;

    //        //    }
    //        //}


    //        else if (module == "Home")
    //        {
    //            switch (catId)
    //            {
    //                case 1:
    //                    control = page.LoadControl(urlAdmin + "Admin/Home.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 2: // Reset Password
    //                    control = page.LoadControl(urlAdmin + "Admin/Alert.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                default:
    //                    control = page.LoadControl(urlAdmin + "Admin/Home.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //            }
    //        }

    //        // Module ben Danh muc
    //        if (module == "Navigation")
    //        {
    //            switch (catId)
    //            {
    //                case 1: // Tao cty thanh vien
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/Navigation/Company.ascx");//	Default.html/Admin/Navigation/1
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 2: // Mon thi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/Navigation/Subject.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 3: // Phan thi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/Navigation/Part.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 4: // Linh vuc
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/Navigation/Field.ascx");
    //                    holder.Controls.Add(control);
    //                    break;

    //                case 5: // Vung mien
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/Navigation/Location.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 6: // Kỳ thi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/Navigation/Contest.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //            }
    //        }//End Module Member

    //        // Module ben Quan ly cau hoi
    //        if (module == "Question")
    //        {
    //            switch (catId)
    //            {
    //                case 1: // Tao cau hoi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/AdminQuestion/QuestionHome.ascx");//	Default.html/Admin/Navigation/1
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 2: // Duyet cau hoi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/AdminQuestion/QuestionApprove.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 3: // Danh sach cau hoi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/AdminQuestion/QuestionList.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 4: // Danh sach cau het han
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/AdminQuestion/QuestionExpireList.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 5: // Danh sach cau loai bo
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/AdminQuestion/QuestionReturnList.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 6: // Chia se cau hoi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/AdminQuestion/QuestionShare.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 7: // Tao cau hoi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/AdminQuestion/QuestionCreate.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //            }
    //        }//End Quan ly cau hoi

    //        // Module ben Quan ly de thi
    //        if (module == "Exam")
    //        {
    //            switch (catId)
    //            {
    //                case 1: // Tao de thi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/AdminExam/ExamCreate.ascx");//	Default.html/Admin/Navigation/1
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 2: // Danh sach de thi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/AdminExam/ExamList.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 3: // Cap nhat de thi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/AdminExam/ExamUpdate.ascx");
    //                    holder.Controls.Add(control);
    //                    break;



    //            }
    //        }//End Quan ly de thi

    //        if (module == "Schedule")//Quan ly dot thi
    //        {
    //            switch (catId)
    //            {
    //                case 1: // Tao dot thi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/AdminSchedule/ScheduleCreate.ascx");//	Default.html/Admin/Navigation/1
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 2: // Danh sach dot thi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/AdminSchedule/ScheduleList.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 3: // Cham bai thi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/AdminSchedule/Marking.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 4: //Cham bai thi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/AdminSchedule/MarkList.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 5: //Cap nhat dot thi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/AdminSchedule/ScheduleUpdate.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 6: // Danh sach dot thi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/AdminSchedule/ResultList.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 7: // Chi tiet de thi thi sinh
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/AdminSchedule/ResultDetail.ascx");
    //                    holder.Controls.Add(control);
    //                    break;

    //            }
    //        }//End Quan ly dot thi

    //        if (module == "Report")//Bao cao
    //        {
    //            switch (catId)
    //            {
    //                case 1: // Bao cao cau hoi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/Report/Question.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 2: // Bao cao de thi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/Report/Exam.ascx");
    //                    holder.Controls.Add(control);
    //                    break;

    //                case 3: // Bao cao ket qua thi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/Report/Result.ascx");
    //                    holder.Controls.Add(control);
    //                    break;

    //                case 4: // Bao cao luot thi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/Report/TestTotal.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 5: // Bao cao ket qua thi theo mon
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/Report/ResultBySubject.ascx");
    //                    holder.Controls.Add(control);
    //                    break;

    //                case 6: // Bao cao thanh vien
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/Report/Member.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //            }
    //        }//End Bao cao


    //        if (module == "Post")//Bai viet
    //        {
    //            switch (catId)
    //            {
    //                case 1: // Tin tuc      
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/ManagementPost/News.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 2: // Lien he
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/ManagementPost/Contact.ascx");
    //                    holder.Controls.Add(control);
    //                    break;

    //                case 3: // Huong dan thi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/ManagementPost/GuideExam.ascx");
    //                    holder.Controls.Add(control);
    //                    break;

    //                case 4: // Lien ket website
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/ManagementPost/LinkWebsite.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 5: // Cap nhat tin tuc
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/ManagementPost/NewsUpdate.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 6: // Cap nhat tin tuc
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/ManagementPost/LinkWebsiteUpdate.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                case 7: // Cap nhat huong dan thi
    //                    control = page.LoadControl(urlAdmin + "Admin/Components/ManagementPost/GuideExamUpdate.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //            }
    //        }//End Bai viet
    //    }
    //    //End admin
    //    #endregion

    //    #region Load Control User
    //    //User 
    //    else
    //    {
    //        if (module == "Home")//Trang chu
    //        {
    //            switch (catId)
    //            {
    //                case 1: // Trang chu
    //                    control = page.LoadControl("Components/Home/Home.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //            }
    //        }

    //        else if (module == "UpdateInfoMember")
    //        {
    //            switch (catId)
    //            {
    //                case 1:// Cap nhat thong tin ca nhan                
    //                    control = page.LoadControl(url + "Components/Member/UpdateInfoMember.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //                default: // Trang chu
    //                    control = page.LoadControl(url + "Components/Home/Home.ascx");
    //                    holder.Controls.Add(control);
    //                    break;
    //            }
    //        }
    //    }
    //    #endregion
    //}
    
       




    #endregion
}
